/*
 * 未完成任务：参数confirmId
 * 点击确认后页面跳转到哪里
 * 与后台人员确认接口数据问题*/
var _PROTOTYPE_ = {
    _init: function () {
        var _this = this;
        var index = layer.load(1, {
            shade: [0.5, '#000']
        });
        $(".exp-fee").find(".deal-type-table").hide();
        $(".imp-fee").find(".deal-type-table").hide();
        $.ajax({
                   url: '/fund/protocol/biz/getSupConfirmData',
                   data: _this._getUrlSearch(),
                   /*data: {"confirmId": "304cd8868fb24ffca54df5ef605cd039"},*/
                   type: 'get',
                   dataType: 'json',
                   success: function (data) {
                       console.log(data);
                       layer.close(index);
                       if (data.result) {
                           _this.data = data.data;
                           $(".customer-table").find(".label-supComName").text(_this.data.supComName);
                           $(".start-time").text(_this.data.timeStart);
                           $(".end-time").text(_this.data.timeEnd);
                           if (!$.isEmptyObject(_this.data.expDetails)) {
                               _this._render("expDetails", ".exp-fee");
                               $(".exp-fee").find(".deal-type-table").show();
                           }
                           if (!$.isEmptyObject(_this.data.impDetails)) {
                               _this._render("impDetails", ".imp-fee");
                               $(".imp-fee").find(".deal-type-table").show();
                           }
                       } else {
                           alert(data.msg);
                       }
                   },
                   error: function (a, b, c) {
                       console.log(b);
                   }
               });
    },
    _getUrlSearch: function () {
        var search = window.location.search.substr(1);
        return search;
    },
    _render: function (obj, target) {
        for (var prop in this.data[obj]) {
            var data = this.data[obj][prop];
            var $cloneTable = $(".fee-table-template").clone().removeClass("fee-table-template");
            $cloneTable.find("thead .label-custom-general").text(prop + ":");
            for (var i = 0; i < data.length; i++) {
                var $cloneTr = $cloneTable.find(".fee-tr-template").clone().removeClass("fee-tr-template");
                $cloneTr.find(".label-feeName").text(data[i].feeName + "：");
                if (data[i].startCount) {
                    $cloneTr.find(".label-startCount").html("第" + "<span class=\"span-number\">"
                                                            + data[i].startCount
                                                            + "</span>").next().text(data[i].countBy.substr(-1)
                                                                                     + "起").next().html("<span class=\"span-fee\">"
                                                                                                        + data[i].unitPrice
                                                                                                        + "</span>").next().text(data[i].countBy);
                    /*if (data[i].startPrice != undefined) {
                     $cloneTr.find(".label-starting").text("起步价").next().text(data[i].startPrice).next().text(data[i].countBy);
                     }*/
                    if (data[i].capPrice != undefined) {
                        $cloneTr.find(".label-cap").text("封顶").next().text(data[i].capPrice).next().text("元");
                    }
                } else {
                    $cloneTr.find(".label-startCount").text(data[i].unitPrice).next().text(data[i].countBy).end().find(".label-descript").text("费用说明：").next().text(data[i].decript);
                }
                if (data[i].decript) {
                    $cloneTr.find(".label-descript").text("费用说明：").next().text(data[i].decript)
                }
                $cloneTable.append($cloneTr);
            }
            $(target).append($cloneTable);
        }
    }
};